<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha256-AbA177XfpSnFEvgpYu1jMygiLabzPCJCRIBtR5jGc0k=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"tomstand.gitee.io","root":"/","images":"/images","scheme":"Muse","darkmode":false,"version":"8.13.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"Searching...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}}</script><script src="/js/config.js"></script>

    <meta name="description" content="分布式存储系统数据库中间件-Mycat 官方文档网站：http:&#x2F;&#x2F;mycat.org.cn&#x2F;  Mycat基本定义 一个彻底开源的，面向企业应用开发的大数据库集群  支持事务、ACID、可以替代MySQL的加强版数据库  一个可以视为MySQL集群的企业级数据库，用来替代昂贵的Oracle集群  一个融合内存缓存技术、NoSQL技术、HDFS大数据的新型SQL Server  结合传统数据库和新">
<meta property="og:type" content="article">
<meta property="og:title" content="猿日记">
<meta property="og:url" content="https://tomstand.gitee.io/2023/11/21/%E5%88%86%E5%B8%83%E5%BC%8F%E5%AD%98%E5%82%A8%E7%B3%BB%E7%BB%9F%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E9%97%B4%E4%BB%B6-Mycat/index.html">
<meta property="og:site_name" content="猿日记">
<meta property="og:description" content="分布式存储系统数据库中间件-Mycat 官方文档网站：http:&#x2F;&#x2F;mycat.org.cn&#x2F;  Mycat基本定义 一个彻底开源的，面向企业应用开发的大数据库集群  支持事务、ACID、可以替代MySQL的加强版数据库  一个可以视为MySQL集群的企业级数据库，用来替代昂贵的Oracle集群  一个融合内存缓存技术、NoSQL技术、HDFS大数据的新型SQL Server  结合传统数据库和新">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/33e2ccb66b426e362ecdfbd3732e526f.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/9183c694d845dd1e2579f3d801106fa5.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/288e1dd7d70294e7e32c153f07f010db.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/6e6a27e9cfe863c83a577e9189d4d879.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/29608250be0c55dfbc6c31bc38ad3bf5.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/7469b5d7e842f0180ba39775290b20bc.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/15befe90f3b2624df3f76d8497cbea2c.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/d381faf352b959c257295d5f59262c1b.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/72838db42b85338c210331950e996d0b.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/ebb32cfe04cc456d360b3a96b7affc56.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/48bdf902353bf3c54b51b938188016b7.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/2e6ab58ed3aedad3a00da7a1bdcaeca0.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/fda149511aa0873e22f6a918f711fdda.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/img_convert/cfc3b4c22d139a44b555a3ddaec7bfd0.png">
<meta property="article:published_time" content="2023-11-21T12:16:19.930Z">
<meta property="article:modified_time" content="2023-11-21T12:16:19.931Z">
<meta property="article:author" content="tomstand">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/img_convert/33e2ccb66b426e362ecdfbd3732e526f.png">


<link rel="canonical" href="https://tomstand.gitee.io/2023/11/21/%E5%88%86%E5%B8%83%E5%BC%8F%E5%AD%98%E5%82%A8%E7%B3%BB%E7%BB%9F%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E9%97%B4%E4%BB%B6-Mycat/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"en","comments":true,"permalink":"https://tomstand.gitee.io/2023/11/21/%E5%88%86%E5%B8%83%E5%BC%8F%E5%AD%98%E5%82%A8%E7%B3%BB%E7%BB%9F%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E9%97%B4%E4%BB%B6-Mycat/","path":"2023/11/21/分布式存储系统数据库中间件-Mycat/","title":""}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title> | 猿日记</title>
  






  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar" role="button">
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">猿日记</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>







</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%86%E5%B8%83%E5%BC%8F%E5%AD%98%E5%82%A8%E7%B3%BB%E7%BB%9F%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E9%97%B4%E4%BB%B6-Mycat"><span class="nav-number">1.</span> <span class="nav-text">分布式存储系统数据库中间件-Mycat</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Mycat%E5%9F%BA%E6%9C%AC%E5%AE%9A%E4%B9%89"><span class="nav-number">1.1.</span> <span class="nav-text">Mycat基本定义</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B8%B8%E7%94%A8%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF"><span class="nav-number">1.2.</span> <span class="nav-text">常用应用场景</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E9%97%B4%E4%BB%B6%E5%9F%BA%E6%9C%AC%E6%9E%B6%E6%9E%84%E5%9B%BE"><span class="nav-number">1.3.</span> <span class="nav-text">数据库中间件基本架构图</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#MySQL%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB%E6%96%B9%E6%A1%88%E5%8F%8AMycat%E6%8E%A5%E5%85%A5"><span class="nav-number">1.4.</span> <span class="nav-text">MySQL读写分离方案及Mycat接入</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Mysql%E9%AB%98%E5%8F%AF%E7%94%A8%E4%B8%8E%E9%9B%86%E7%BE%A4%E6%96%B9%E6%A1%88%E5%8F%8AMycat%E6%8E%A5%E5%85%A5%E5%A4%84%E7%90%86"><span class="nav-number">1.5.</span> <span class="nav-text">Mysql高可用与集群方案及Mycat接入处理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Mycat%E6%80%BB%E4%BD%93%E6%9E%B6%E6%9E%84%E5%AE%9E%E7%8E%B0"><span class="nav-number">1.6.</span> <span class="nav-text">Mycat总体架构实现</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Mycat%E7%BD%91%E7%BB%9CIO%E6%9E%B6%E6%9E%84%E4%B8%8E%E5%AE%9E%E7%8E%B0"><span class="nav-number">1.7.</span> <span class="nav-text">Mycat网络IO架构与实现</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Mycat%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5"><span class="nav-number">1.8.</span> <span class="nav-text">Mycat最佳实践</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">tomstand</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">12</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="Back to top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="en">
    <link itemprop="mainEntityOfPage" href="https://tomstand.gitee.io/2023/11/21/%E5%88%86%E5%B8%83%E5%BC%8F%E5%AD%98%E5%82%A8%E7%B3%BB%E7%BB%9F%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E9%97%B4%E4%BB%B6-Mycat/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="tomstand">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="猿日记">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content=" | 猿日记">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2023-11-21 20:16:19" itemprop="dateCreated datePublished" datetime="2023-11-21T20:16:19+08:00">2023-11-21</time>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="分布式存储系统数据库中间件-Mycat"><a href="#分布式存储系统数据库中间件-Mycat" class="headerlink" title="分布式存储系统数据库中间件-Mycat"></a>分布式存储系统数据库中间件-Mycat</h2><blockquote>
<p>官方文档网站：<a target="_blank" rel="noopener" href="http://mycat.org.cn/">http://mycat.org.cn/</a></p>
</blockquote>
<h3 id="Mycat基本定义"><a href="#Mycat基本定义" class="headerlink" title="Mycat基本定义"></a>Mycat基本定义</h3><ul>
<li><p>一个彻底开源的，面向企业应用开发的大数据库集群</p>
</li>
<li><p>支持事务、ACID、可以替代MySQL的加强版数据库</p>
</li>
<li><p>一个可以视为MySQL集群的企业级数据库，用来替代昂贵的Oracle集群</p>
</li>
<li><p>一个融合内存缓存技术、NoSQL技术、HDFS大数据的新型SQL Server</p>
</li>
<li><p>结合传统数据库和新型分布式数据仓库的新一代企业级数据库产品</p>
</li>
<li><p>一个新颖的数据库中间件产品</p>
</li>
</ul>
<h3 id="常用应用场景"><a href="#常用应用场景" class="headerlink" title="常用应用场景"></a>常用应用场景</h3><ul>
<li>单纯的读写分离，本身支持读写分离，主从切换</li>
<li>分库分表，对于超过1000万的表进行分片，最大支持1000亿的单表分片</li>
<li>多租户应用，每个应用一个库，但应用程序只是连接Mycat,从而不改造程序本身，实现多租户化</li>
<li>报表系统，借助于Mycat的分表能力，处理大规模报表的统计</li>
<li>替代Hbase，分析大数据</li>
<li>作为海量数据实时查询的一种简单有效方案，比如100亿条频繁查询的记录需要在3秒内查询出来结果，除了基于主键的查询，还可能存在范围查询或其他属性查询，此时Mycat可能是最简单有效的选择</li>
</ul>
<h3 id="数据库中间件基本架构图"><a href="#数据库中间件基本架构图" class="headerlink" title="数据库中间件基本架构图"></a>数据库中间件基本架构图</h3><p><img src="https://img-blog.csdnimg.cn/img_convert/33e2ccb66b426e362ecdfbd3732e526f.png" alt="image-20201223111136623"></p>
<p>中间件是介于数据库和应用之间，进行数据处理和交互的中间服务，能有效的管理数据底层的交互处理，让应用只需要集中在业务处理上，底层的数据让中间件来处理，提高整个系统的稳定性和扩展性</p>
<h3 id="MySQL读写分离方案及Mycat接入"><a href="#MySQL读写分离方案及Mycat接入" class="headerlink" title="MySQL读写分离方案及Mycat接入"></a>MySQL读写分离方案及Mycat接入</h3><p>标准的读写分离方案是主从模式，一个主节点负责数据写入，多个从节点负责数据读取，通常是1个主节点写入对应3个从节点读取数据</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/9183c694d845dd1e2579f3d801106fa5.png" alt="image-20201223143556191"></p>
<p>Mycat不负责mysql的数据同步问题，只负责sql读写分离资源的分开和管控</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/288e1dd7d70294e7e32c153f07f010db.png" alt="image-20201224110514629"></p>
<p>Mycat中执行以下两种配置即可接入mysql的主从配置</p>
<h3 id="Mysql高可用与集群方案及Mycat接入处理"><a href="#Mysql高可用与集群方案及Mycat接入处理" class="headerlink" title="Mysql高可用与集群方案及Mycat接入处理"></a>Mysql高可用与集群方案及Mycat接入处理</h3><p><img src="https://img-blog.csdnimg.cn/img_convert/6e6a27e9cfe863c83a577e9189d4d879.png" alt="image-20201224111127167"></p>
<p>对实时性要求不高的应用可以采用多台低配置的PC server扩展Slave的数量，将读压力分配到Slave上，解决数据库的读性能瓶颈，很多中小型网站采用此方式解决数据库压力</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/29608250be0c55dfbc6c31bc38ad3bf5.png" alt="image-20201224111455006"></p>
<p>MySQL Cluster使用不是很普遍，主要原因是配置管理负责，运维难度比较大并且存在安全问题</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/7469b5d7e842f0180ba39775290b20bc.png" alt="image-20201224111711196"></p>
<p>heartbeat是linux-HA工程的一个组件，核心包括两个：心跳检测和资源接管，指定时间内未收到对方发送的报文就认为是失败的，这是需要启动资源接管模块接管运行在对方主机上的资源服务</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/15befe90f3b2624df3f76d8497cbea2c.png" alt="image-20201224111900260"></p>
<p>PRBD是通过网络来实现设备的数据镜像同步的开源Cluster软件，它自动完成网络中两个不同服务器上的磁盘同步，相对于binlog日志同步，它是底层的磁盘同步，理论上是和很多文件系统的高可用配置</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/d381faf352b959c257295d5f59262c1b.png" alt="image-20201224112055633"></p>
<p>Lvs是一个虚拟的服务器集群系统，可以实现linux平台下的简单负载均衡，keepalived主要用于主机和备机的故障转移，是一种适用面很广的负载均衡和高可用方案，常用于Web系统上</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/72838db42b85338c210331950e996d0b.png" alt="image-20201224113102686"></p>
<p>Mycat的高可用官方推荐是采用Haproxt+keepalived的方式功能稳定性也比较好</p>
<h3 id="Mycat总体架构实现"><a href="#Mycat总体架构实现" class="headerlink" title="Mycat总体架构实现"></a>Mycat总体架构实现</h3><p><img src="https://img-blog.csdnimg.cn/img_convert/ebb32cfe04cc456d360b3a96b7affc56.png" alt="image-20201224122608348"></p>
<h3 id="Mycat网络IO架构与实现"><a href="#Mycat网络IO架构与实现" class="headerlink" title="Mycat网络IO架构与实现"></a>Mycat网络IO架构与实现</h3><p>Mycat同时实现了NIO和AIO，可以通过系统参数选择是使用AIO还是NIO</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/48bdf902353bf3c54b51b938188016b7.png" alt="image-20201224121631599"></p>
<p>核心包含四个处理时间：客户端连接服务端事件、服务端接受客户端连接事件、读事件、写事件</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/2e6ab58ed3aedad3a00da7a1bdcaeca0.png" alt="image-20201224121819682"></p>
<p>相比于AIO简单的架构，NIO应用场景比较复杂，在高性能IO框架中都会应用到NIO</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/fda149511aa0873e22f6a918f711fdda.png" alt="image-20201224122218833"></p>
<h3 id="Mycat最佳实践"><a href="#Mycat最佳实践" class="headerlink" title="Mycat最佳实践"></a>Mycat最佳实践</h3><p><img src="https://img-blog.csdnimg.cn/img_convert/cfc3b4c22d139a44b555a3ddaec7bfd0.png" alt="image-20201224120724654"></p>
<p>这种方案基本包含Mycat能满足和实现的全部实现方案</p>

    </div>

    
    
    

    <footer class="post-footer">

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2023/11/21/hello-world/" rel="prev" title="Hello World">
                  <i class="fa fa-chevron-left"></i> Hello World
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2023/11/21/%E5%88%86%E5%B8%83%E5%BC%8F%E5%8D%8F%E8%B0%83%E6%9C%8D%E5%8A%A1-Zookeeper/" rel="next" title="">
                   <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">tomstand</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" rel="noopener" target="_blank">NexT.Muse</a>
  </div>

    </div>
  </footer>

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  





  





</body>
</html>
